<!--注册页面-->
<?php 
session_start();
//引入数据库
$data=include"./data.php";
//引入函数库
include "./function.php";
//判定上传的方式是否是post
	if(IS_POST){
		//判定验证码是否输入正确
		if($_POST['code']==$_SESSION['code']){
//			删除验证码
			unset($_POST['code']);
		}else{
			success('验证码输入不正确');
		}
//		判定再次确认密码和密码是否相同
		if($_POST['password']==$_POST['apassword']){
//			如果相同就删了apassword
			unset($_POST['apassword']);
		}else{
			success('两次密码输入不相同');
		}
//	定义一个状态变量
		$state='';
//		使用foreach循环，循环数据库里面的数据
		foreach($data as $v){
			//判定提交的昵称与数据库里面的数据是否重用
			if($_POST['nickname']==$v['nickname']&&$_POST['ID']==$v['ID']){
				$state=FALSE;
			}else{
				$state=TRUE;
			}
		}
//		判定状态变量的值
//如果是true就进行数据传送，如果是false就报错
		if($state){
//			密码加密
			$_POST['password']=md5($_POST['password']);
//			压入数据库
			$data[]=$_POST;
//			转换为字符串
			$data=var_export($data,true);
//			写入数据
			file_put_contents("./data.php","<?php return \n".$data."?>");
//			成功跳转
			success('注册成功，立即加入战斗吧');
		}else{
			success('注册失败，昵称或账号已存在');
		}
		
	}

 ?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
	<title>欢迎注册</title>
	<script type="text/javascript">
		$(function(){
			$('#change').click(function(){
				var src=$('.code').attr('src');
				var fulldest=src+'?'+Math.random();
				$('.code').attr('src',fulldest);
			})
		})
	</script>
	<style type="text/css">
		*{
			padding: 0;
			margin: 0;
		}
		li{
			list-style: none;
		}
		body{
			width:1200px;
			height: 665px;
			background: url(image/03.jpg) no-repeat 0px 0px;
			background-size: 100% 100%;
			position: relative;
		}
		#box{
			width: 480px;
			height: 540px;
			border: 1px solid #666666;
			position: absolute;
			top: 50px;
			left:400px;
			background:url(image/05.JPG) no-repeat -230px -50px ;
			opacity: 0.9;
		}
		#box .title{
			width:480px;
			height:100px;
			border-bottom: 1px solid #111111;
			line-height:100px;
			text-align: center;
			font-size: 50px;
			font-family: "微软雅黑";
			color: darkred;
			letter-spacing: 9px;
		}
		#box .zhuce{
			width:375px;
			height:400px;
			/*border: 1px solid blue;*/
			margin-top: 20px;
			margin-left:50px;
		}
		#box form{
			width: 375px;
			height: 400px;
			position: relative;
		}
		#box form ul{
			width: 375px;
			height: 195px;
			/*border-bottom: 1px solid red;*/
		}
		#box form ul li{
			width: 375px;
			height: 48px;
			line-height:48px;
			text-indent: 30px;
		}
		#box form ul li input{
			border: none;
			background:#ABC9DB;
			width: 220px;
			height: 30px;
			border-bottom: 1px dashed #666666;
			font-size: 20px;
			font-family: "微软雅黑";
			color: black;
		}
		#box form ul li span{
			font-size:23px;
			font-family: "微软雅黑";
			color: red;
		}
		#box form img{
			display: block;
			width: 185px;
			height: 80px;
			position: absolute;
			top:240px;
			left: 50px;
		}
		#box form #change{
			display: block;
			width: 95px;
			height: 20px;
			position: absolute;
			top: 270px;
			right: 30px;
			font-size:15px;
		}
		#box form .checkbox{
			width: 260px;
			height: 20px;
			/*border: 1px solid red;*/
			position: absolute;
			top: 330px;
			left: 50px;
		}
		#box form .checkbox input{
			width: 20px;
			height: 20px;
			float: left;
		}
		#box form .checkbox p{
			width: 230px;
			height: 20px;
			float: left;
		}
	</style>
</head>
<body>
	<div id="box">
		<!--标题-->
		<p class="title">欢迎加入我们!</p>
		<!--标题结束-->
		<!--注册接入口-->
		<div class="zhuce">
			<!--form表单-->
			<form action="" method="post">
				<ul>
					<li><span>昵称:</span><input type="text" name="nickname" id="" value="给自己起个响亮的称号吧"  onfocus="javascript:if(this.value=='给自己起个响亮的称号吧')this.value='';"/></li>
					<li><span>账号:</span><input type="ID" name="ID" id="ID" value="输入账号" onfocus="javascript:if(this.value=='输入账号')this.value='';"/></li>
					<li><span>密码:</span><input type="password" name="password" id="password" value="" /></li>
					<li><span>确认密码:</span><input type="password" name="apassword" id="password" value="" /></li>
					<li><span>验证码:</span><input type="text" name="code" id="code" value="请输入验证码" /></li>
				</ul>
				<img src="./Code.class.php" onclick="this.src=this.src+'?'+Math.random()" alt="" class="code"/>
				<a href="javascript:;" id="change">看不清换一个</a><br />
				<div class="checkbox">
					<input type="checkbox" name="cx" class="cx" value="" /><p style="color: white;">《同意遵守公平游戏用户手册》</p>
				</div>
				<input type="submit" value="确认注册" style="width:160px;height: 45px;position: absolute;bottom:0px;left:100px;font-size: 25px;background: white;"/>
			</form>
			<!--form表单结束-->
		</div>
		<!--注册接入口结束-->
	</div>
</body>
</html>